package com.f5.management.service.impl;

import com.f5.management.dao.ActivityDAO;
import com.f5.management.entity.Activity;
import com.f5.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityDAO activityDAO;

    @Override
    @Transactional
    public void updateActivity(Activity activity) {
        int id = activity.getId();

        Activity data = activityDAO.get(id);
        // 0--失效，1--有效
        int status = data.getStatus();
        if(status == 0) {
            throw new RuntimeException("活动失效，无法修改");
        }
        activityDAO.update(activity);
    }

    @Override
    public void insertActivity(Activity activity) {
        activityDAO.insert(activity);
    }

    @Override
    public void deleteActivity(int id) {
        activityDAO.delete(id);
    }

    @Override
    public Activity selectActivity(int id) {
        return activityDAO.get(id);
    }

    @Override
    public List<Activity> list() {
        return activityDAO.list();
    }

    @Override
    public int count() {
        return activityDAO.count();
    }

}
